Repository navigation
gh-123726: Document caveats of zipfile.Path around name sanitization - #130537
Merged
Merged
Conversation
…ation Add a note to the `zipfile.Path` class documentation clarifying that it does not sanitize filenames. This emphasizes the caller's responsibility to validate or sanitize inputs, especially when handling untrusted ZIP archives, to prevent path traversal vulnerabilities. The note also references the `extract` and `extractall` methods for comparison and suggests using `os.path.abspath` and `os.path.commonpath` for safe filename resolution.
|
Thanks @AffanShaikhsurab for the PR, and @jaraco for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13. |
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this pull request
Mar 8, 2025
…ation (pythonGH-130537) Add a note to the `zipfile.Path` class documentation clarifying that it does not sanitize filenames. This emphasizes the caller's responsibility to validate or sanitize inputs, especially when handling untrusted ZIP archives, to prevent path traversal vulnerabilities. The note also references the `extract` and `extractall` methods for comparison and suggests using `os.path.abspath` and `os.path.commonpath` for safe filename resolution. (cherry picked from commit a3990df) Co-authored-by: Affan Shaikhsurab <51104750+AffanShaikhsurab@users.noreply.github.com>
|
GH-130986 is a backport of this pull request to the 3.13 branch. |
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this pull request
Mar 8, 2025
…ation (pythonGH-130537) Add a note to the `zipfile.Path` class documentation clarifying that it does not sanitize filenames. This emphasizes the caller's responsibility to validate or sanitize inputs, especially when handling untrusted ZIP archives, to prevent path traversal vulnerabilities. The note also references the `extract` and `extractall` methods for comparison and suggests using `os.path.abspath` and `os.path.commonpath` for safe filename resolution. (cherry picked from commit a3990df) Co-authored-by: Affan Shaikhsurab <51104750+AffanShaikhsurab@users.noreply.github.com>
|
GH-130987 is a backport of this pull request to the 3.12 branch. |
jaraco
reviewed
Mar 8, 2025
jaraco
left a comment
Member
There was a problem hiding this comment.
I read this over a few times. I considered changing it to point out that it's mostly relevant when manifesting names in a file system, or making a reference to the open issues around providing a sanitizing extractor, but decided against that. This is a good, complete contribution. Thanks!
jaraco
pushed a commit
that referenced
this pull request
Mar 8, 2025
…zation (GH-130537) (#130986) gh-123726: Document caveats of zipfile.Path around name sanitization (GH-130537) Add a note to the `zipfile.Path` class documentation clarifying that it does not sanitize filenames. This emphasizes the caller's responsibility to validate or sanitize inputs, especially when handling untrusted ZIP archives, to prevent path traversal vulnerabilities. The note also references the `extract` and `extractall` methods for comparison and suggests using `os.path.abspath` and `os.path.commonpath` for safe filename resolution. (cherry picked from commit a3990df) Co-authored-by: Affan Shaikhsurab <51104750+AffanShaikhsurab@users.noreply.github.com>
jaraco
pushed a commit
that referenced
this pull request
Mar 8, 2025
…zation (GH-130537) (#130987) gh-123726: Document caveats of zipfile.Path around name sanitization (GH-130537) Add a note to the `zipfile.Path` class documentation clarifying that it does not sanitize filenames. This emphasizes the caller's responsibility to validate or sanitize inputs, especially when handling untrusted ZIP archives, to prevent path traversal vulnerabilities. The note also references the `extract` and `extractall` methods for comparison and suggests using `os.path.abspath` and `os.path.commonpath` for safe filename resolution. (cherry picked from commit a3990df) Co-authored-by: Affan Shaikhsurab <51104750+AffanShaikhsurab@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a note to the
zipfile.Pathclass documentation clarifying that it does not sanitize filenames. This emphasizes the caller's responsibility to validate or sanitize inputs, especially when handling untrusted ZIP archives, to prevent path traversal vulnerabilities. The note also references theextractandextractallmethods for comparison and suggests usingos.path.abspathandos.path.commonpathfor safe filename resolution.This Pr solves the issue #123726
zipfile.Patharound name sanitization #123726📚 Documentation preview 📚: https://cpython-previews--130537.org.readthedocs.build/